using RuoVea.ExEnum;
using RuoVea.ExSugar.Attributes;
using RuoVea.ExSugar.Entity;
using SqlSugar;
using System.ComponentModel.DataAnnotations;

namespace RuoVea.OmiApi.Reports.Models;

/// <summary>
/// 报表查询SQL字段配置
/// </summary>
[SugarTable(nameof(RptSqlColumn), "报表查询SQL字段配置")]
[SugarIndex($"IX_{nameof(RptSqlColumn)}_{nameof(SqlId)}", nameof(SqlId), OrderByType.Asc)]
[SugarIndex($"IX_{nameof(RptSqlColumn)}_{nameof(CreateTime)}", nameof(CreateTime), OrderByType.Desc)]
public class RptSqlColumn : EntityBase
{
    /// <summary>
    /// 绑定的SQL ID
    /// </summary>
    [ConfigSugarColumn(nameof(SqlId),columnDescription : "SQL ID")]
    public long? SqlId { get; set; }

    /// <summary>
    /// SQL查询字段名
    /// </summary>
    [Required, MaxLength(100)]
    [ConfigSugarColumn(nameof(SqlField),columnDescription : "查询字段名", Length = 100)]
    public string SqlField { get; set; }

    /// <summary>
    /// 列显示名称
    /// </summary>
    [MaxLength(100)]
    [ConfigSugarColumn(nameof(ColumnName),columnDescription : "列显示名称", IsNullable = true, Length = 100)]
    public string ColumnName { get; set; }

    /// <summary>
    /// 是否列表字段
    /// </summary>
    [ConfigSugarColumn(nameof(IsList),columnDescription : "是否列表字段", IsNullable = true, DefaultValue = "0")]
    public YesOrNot? IsList { get; set; } = YesOrNot.N;

    /// <summary>
    /// 对齐方式
    /// </summary>
    [MaxLength(20)]
    [ConfigSugarColumn(nameof(Align),columnDescription : "对齐方式", IsNullable = true, Length = 20)]
    public string Align { get; set; } = "left";

    /// <summary>
    /// 显示类型
    /// </summary>
    [MaxLength(50)]
    [ConfigSugarColumn(nameof(HtmlType),columnDescription : "显示类型", IsNullable = true, Length = 50)]
    public string HtmlType { get; set; }

    /// <summary>
    /// 是否导出字段
    /// </summary>
    [ConfigSugarColumn(nameof(IsExport),columnDescription : "是否导出字段", IsNullable = true, DefaultValue = "1")]
    public YesOrNot? IsExport { get; set; } = YesOrNot.Y;

    /// <summary>
    /// 是否查询字段
    /// </summary>
    [ConfigSugarColumn(nameof(IsQuery),columnDescription : "是否查询字段", IsNullable = true, DefaultValue = "0")]
    public YesOrNot? IsQuery { get; set; } = YesOrNot.N;

    /// <summary>
    /// 是否隐藏
    /// </summary>
    [ConfigSugarColumn(nameof(IsHidden),columnDescription : "是否隐藏", DefaultValue = "0")]
    public YesOrNot? IsHidden { get; set; } = YesOrNot.N;

    /// <summary>
    /// 查询控件类型
    /// </summary>
    [MaxLength(50)]
    [ConfigSugarColumn(nameof(HtmlTypeQuery),columnDescription : "查询控件类型", IsNullable = true, Length = 50)]
    public string HtmlTypeQuery { get; set; }

    /// <summary>
    /// 查询方式
    /// </summary>
    [MaxLength(20)]
    [ConfigSugarColumn(nameof(QueryType),columnDescription : "查询方式", IsNullable = true, Length = 20)]
    public string QueryType { get; set; }

    /// <summary>
    /// 是否仅作为参数
    /// </summary>
    [ConfigSugarColumn(nameof(IsParameterOnly),columnDescription : "是否仅参数", IsNullable = true, DefaultValue = "0")]
    public YesOrNot? IsParameterOnly { get; set; } = YesOrNot.N;

    /// <summary>
    /// 测试参数值
    /// </summary>
    [MaxLength(200)]
    [ConfigSugarColumn(nameof(TestValue),columnDescription : "测试参数值", IsNullable = true, Length = 200)]
    public string TestValue { get; set; }

    /// <summary>
    /// 字典类型
    /// </summary>
    [MaxLength(100)]
    [ConfigSugarColumn(nameof(DictType),columnDescription : "字典类型", IsNullable = true, Length = 100)]
    public string DictType { get; set; }

    /// <summary>
    /// 格式化脚本
    /// </summary>
    [ConfigSugarColumn(nameof(Formatter),columnDescription : "格式化脚本", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)]
    public string Formatter { get; set; }

    /// <summary>
    /// 是否有子级
    /// </summary>
    [ConfigSugarColumn(nameof(HasChild),columnDescription : "是否有子级", DefaultValue = "0")]
    public YesOrNot? HasChild { get; set; } = YesOrNot.N;

    /// <summary>
    /// 排序号
    /// </summary>
    [ConfigSugarColumn(nameof(OrdinalNo),columnDescription : "排序号", IsNullable = true, DefaultValue = "0")]
    public int? OrdinalNo { get; set; } = 0;

    /// <summary>
    /// API接口返回数据路径
    /// </summary>
    [MaxLength(200)]
    [ConfigSugarColumn(nameof(XPath),columnDescription : "数据路径", IsNullable = true, Length = 200)]
    public string XPath { get; set; }

    /// <summary>
    /// 列宽度(px)
    /// </summary>
    [ConfigSugarColumn(nameof(Width),columnDescription : "列宽度", IsNullable = true)]
    public int? Width { get; set; }

    /// <summary>
    /// 是否总计
    /// </summary>
    [ConfigSugarColumn(nameof(IsAggregate),columnDescription : "是否总计", DefaultValue = "0")]
    public YesOrNot? IsAggregate { get; set; } = YesOrNot.N;

    /// <summary>
    /// 数据类型
    /// </summary>
    [MaxLength(50)]
    [ConfigSugarColumn(nameof(DataType),columnDescription : "数据类型", IsNullable = true, Length = 50)]
    public string DataType { get; set; }

    /// <summary>
    /// 是否输出参数
    /// </summary>
    [ConfigSugarColumn(nameof(IsOutput),columnDescription : "是否输出参数", DefaultValue = "0")]
    public YesOrNot? IsOutput { get; set; } = YesOrNot.N;

    /// <summary>
    /// 组件类型
    /// </summary>
    [MaxLength(50)]
    [ConfigSugarColumn(nameof(ComponentType),columnDescription : "组件类型", IsNullable = true, Length = 50)]
    public string ComponentType { get; set; }

    /// <summary>
    /// 是否可排序
    /// </summary>
    [ConfigSugarColumn(nameof(IsSortable),columnDescription : "是否可排序", DefaultValue = "0")]
    public YesOrNot? IsSortable { get; set; } = YesOrNot.N;

    /// <summary>
    /// 栅格布局配置
    /// </summary>
    [ConfigSugarColumn(nameof(GridItem),columnDescription : "栅格布局", IsNullable = true, ColumnDataType = StaticConfig.CodeFirst_BigString)]
    public string GridItem { get; set; }

    /// <summary>
    /// 映射目标属性
    /// </summary>
    [MaxLength(100)]
    [ConfigSugarColumn(nameof(MappingTarget),columnDescription : "映射目标", IsNullable = true, Length = 100)]
    public string MappingTarget { get; set; }

    /// <summary>
    /// 父节点ID
    /// </summary>
    [ConfigSugarColumn(nameof(ParentId),columnDescription : "父节点ID", IsNullable = true, DefaultValue = "0")]
    public long? ParentId { get; set; } = 0;
}